gh-150075: tar.addfile() doesn't set member offsets#150278
gh-150075: tar.addfile() doesn't set member offsets#150278grantlouisherman wants to merge 1 commit into
Conversation
…file Signed-off-by: grantlouisherman <grantlouisherman041@gmail.com>
| self.offset += len(buf) | ||
| # add original offset to block size | ||
| bufsize=self.copybufsize | ||
| tarinfo.offset_data = self.offset |
There was a problem hiding this comment.
hi there, this seems wrong. you are replacing information about where the file data starts with information about where the file header starts.
|
Hi, I'm a Python dev with some free time on their hands. @grantlouisherman looking through the code for this file, tarfile.offset is available "When TarFile is opened for reading" https://github.com/python/cpython/blob/main/Lib/tarfile.py#L2832 it makes sense that inside the context of writing TarInfo objects to the archive, that offset will not be accessible on the objects themselves at that time. it's not necessarily a bug just because you can't access it, even if your LLM told you it thinks there is a bug. i see in your PR that you potentially copied some wrong attributes (copying offset into offset_data). think about the ramifications of that, and what that means for your test.. other ways to improve your tests are to assert against fixed, known values. otherwise your test can be reporting all value comparisons are correct but if they are all zeroes then it may be a false positive. i also noticed that this is your third attempt to open a pull request with these changes, the previous two being closed because you were not sure of the correct git operations to do to update your branch. learning Please reply with:
|
Original bug report:
Bug report
Bug description:
It appears that
tarfile.TarFile.addfile()sets neitheroffsetnoroffset_dataattributes in theTarInfoadded toself.members, when it's done adding the file. Members in a reopened TAR have correct values.Reproducer
Expected output
Actual output
CPython versions tested on:
3.15
Operating systems tested on:
Linux
Fix
I added the offset info for a given file based on the current offset of the file and then after the block size is calculated. I also included a test to validate the behavior